/**
* Created by ren on 2017/1/7.
*/
<template>
  <div class='comment'>
    <div class="ct" style="margin: 0 20px;padding:0 10px;border-bottom: 1px solid #cccccc">
      <template v-for="(item,index) in commentData.shopping">
        <div class="goods" style="height: 130px;padding: 20px 0;margin: 0 10px">
          <img v-lazy="loadImg(item.imgUrl)"
               style="width: 90px;height: 90px;float: left;border: 1px solid #cccccc;margin-right: 20px">
          <div style="float:left;margin-right: 20px;margin-top: 10px">
            <div class="name">{{item.shopName}}</div>
            <div style="font-size: 16px;color: #666666">
              {{(item.shopstandardVo.weight/1000).toFixed(2)}}x{{commentData.buyNumber}}
            </div>
          </div>
          <div class="desc">
          </div>
          <div style="float:right;font-size: 18px;color: #f05120;margin-top: 20px">￥<span
            style="font-size: 24px">{{(item.shopstandardVo.shopPrice/100).toFixed(2).split('.')[0]}}</span>.{{(item.shopstandardVo.shopPrice/100).toFixed(2).split('.')[1]}}
          </div>
        </div>
        <textarea name="" cols="200" rows="100"
                  style="max-width: 100%;max-height: 250px;border: 1px solid #cccccc;padding: 10px;margin-bottom: 20px"
                  placeholder="你觉得这款产品怎么样？快来告诉大家吧！" v-model="item.content"></textarea>
      </template>
    </div>
    <button class="btn" @click="saveComment">确认评价</button>
    <Notify :parentThis='this'></Notify>
  </div>
</template>

<script>
  import API from '../../api'
  import Notify from '../Notify'
  export default {
    name: 'comment',
    components: {
      Notify
    },
    data: function () {
      return {
        commentData: '',
        notifyStatus: 2
      }
    },
    props: ['_parentThis'],
    methods: {
      loadImg: function (path) {
        return API.path + path
      },
      saveComment: function () {
        for (var i in this.commentData.shopping) {
          var item = this.commentData.shopping[i]
          if (item.content !== '') {
            this.$http.post(API.saveComment, {
              userId: this.$cookie.get('id'),
              content: item.content,
              objectId: item.id,
              orderNo: this.commentData.orderNo,
              standardId: item.shopstandardVo.id
            }).then((ret) => {
              const result = ret.body
              if (result.code === 1) {
                this.notifyStatus = '1|评论成功'
                setTimeout(() => {
                  this.$router.go(-1)
                }, 2000)
              } else {
                this.notifyStatus = '0|' + result.message
              }
            }, (err) => {
              console.log(err)
            })
          } else {
            this.notifyStatus = '0|评论内容不能为空！'
          }
        }
      }
    },
    mounted: function () {
      this.commentData = this.$route.params.commentData
      if (!this.commentData) {
        window.location.href = '/more/moreGoods'
      }
      this._parentThis.titHtml = '<span>购买记录 > <span>商城</span> > <span style="color: #f48315;">评价</span></span>'
      for (var i in this.commentData.shopping) {
        this.commentData.shopping[i].content = ''
      }
    }
  }
</script>
